package com.example.mvvm_base.mvvm.db;

import android.app.Application;

import androidx.room.Room;

public class AppDateBaseUtils {
    private static final String DATE_BASE_NAME="name.db";
    private static  volatile AppDateBaseUtils appDateBaseUtils;
    private AppDateBase appDateBase;
    private UserDao userDao;
    private MoneyDao moneyDao;

    private AppDateBaseUtils() {
    }
    public static AppDateBaseUtils getInstance(){
        if(appDateBaseUtils==null){
            synchronized (AppDateBaseUtils.class){
                if(appDateBaseUtils==null){
                    appDateBaseUtils=new AppDateBaseUtils();
                }
            }
        }
        return appDateBaseUtils;
    }
    public void init(Application application){
        appDateBase= Room.databaseBuilder(application,AppDateBase.class,DATE_BASE_NAME)
                .allowMainThreadQueries()
                .build();
        userDao= appDateBase.getUserDao();
        moneyDao=appDateBase.getMoneyDao();

    }
    public UserDao getUserDao(){
        if(userDao==null){
            userDao= appDateBase.getUserDao();
        }
        return userDao;
    }
    public MoneyDao getMoneyDao(){
        if(moneyDao==null){
            moneyDao=appDateBase.getMoneyDao();
        }
        return moneyDao;
    }
}
